package com.haste.system.controller;

import com.haste.common.domain.po.BaseDictPo;
import com.haste.common.domain.vo.ResponseVo;
import com.haste.common.service.IBaseDictService;
import com.haste.system.domain.vo.TreeNode;
import com.haste.system.service.IDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author haste
 */
@RestController
@RequestMapping("/dict")
@Api(tags = {"字典管理"})
public class DictController {
    @Resource
    private IBaseDictService baseDictService;
    @Resource
    private IDictService dictService;

    @PostMapping("/insert")
    @ApiOperation(value = "新增字典")
    public ResponseVo insert(@RequestBody BaseDictPo baseDictPo){
        dictService.save(baseDictPo);
        return new ResponseVo<>().ok();
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改字典")
    public ResponseVo update(@RequestBody BaseDictPo baseDictPo){
        baseDictService.updateById(baseDictPo);
        return new ResponseVo<>().ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除字典")
    public ResponseVo delete(@PathVariable String id){
        baseDictService.removeById(id);
        return new ResponseVo<>().ok();
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询字典列表")
    public ResponseVo<List<BaseDictPo>> list(){
        return new ResponseVo().ok(baseDictService.list());
    }

    @PostMapping("/tree")
    @ApiOperation(value = "查询字典树列表")
    public ResponseVo<List<TreeNode>> tree(){
        return new ResponseVo().ok(dictService.tree());
    }
}
